import socket

def start_server(host='127.0.0.1', port=6666):
    # 创建 TCP socket
    server_socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
    
    # 绑定 IP 和端口
    server_socket.bind((host, port))
    
    # 开始监听连接
    server_socket.listen(1)
    print(f"服务器启动，监听 {host}:{port}...")
    
    # 接受客户端连接
    client_socket, addr = server_socket.accept()
    print(f"连接来自 {addr}")
    
    while True:
        # 接收数据
        data = client_socket.recv(1024)
        if not data:
            break
        print(f"收到数据: {data.decode()}")
        
        # 发送确认信息
        response = "数据已接收"
        client_socket.send(response.encode())
    
    # 关闭连接
    client_socket.close()
    server_socket.close()

if __name__ == "__main__":
    start_server()

